package com.ytxg.controller.front;


import com.google.gson.Gson;
import com.ytxg.dto.BookCommentDto;
import com.ytxg.dto.BookInfoRespDto;
import com.ytxg.dto.BookRankRespDto;
import com.ytxg.dto.BookVisitDto;
import com.ytxg.service.IBookInfoService;
import com.ytxg.util.resp.RestResp;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/front/book")
public class BookController {

    @Resource
    private IBookInfoService iBookInfoService;

    /**
     * 点击榜单
     * @return
     */
    @GetMapping("visit_rank")
    public RestResp<List<BookRankRespDto>> visitRank() {

        RestResp<List<BookRankRespDto>> bookOrdByVisit = iBookInfoService.getBookOrdByVisit();

        return bookOrdByVisit;
    }

    /**
     * 新书榜单
     * @return
     */
    @GetMapping("newest_rank")
    public RestResp<List<BookRankRespDto>> newestRank() {
        RestResp<List<BookRankRespDto>> bookRank = iBookInfoService.getBookRank();

        return bookRank;
    }

    /**
     * 更新榜单
     * @return
     */
    @GetMapping("update_rank")
    public RestResp<List<BookRankRespDto>> updateRank(){
        RestResp<List<BookRankRespDto>> bookUpdateRank = iBookInfoService.getBookUpdateRank();
        return bookUpdateRank;
    }

    /**
     * 点击量增加
     * @return
     */
    @PostMapping("visit")
    public RestResp visit(@RequestBody BookVisitDto bookVisitDto){
        String id = bookVisitDto.getBookId();
        iBookInfoService.addVisit(Long.parseLong(id));
        return RestResp.ok();
    }

    /**
     * 同类推荐
     * @param bookId
     * @return
     */
    @GetMapping("rec_list")
    public RestResp recList(Long bookId){

        RestResp<List<BookInfoRespDto>> recList = iBookInfoService.getRecList(bookId);

        return recList;
    }

    /**
     * 评论
     * @param bookId
     * @return
     */
    @GetMapping("comment/newest_list")
    public RestResp newestList(Long bookId){
        RestResp<BookCommentDto> newestList = iBookInfoService.getNewestList(bookId);

        return newestList;
    }

    /**
     * 最新章节
     * @param bookId
     * @return
     */
    @GetMapping("last_chapter/about")
    public RestResp about(Long bookId){
        RestResp bookAbout = iBookInfoService.getBookAbout(bookId);

        return bookAbout;
    }

    @GetMapping("category/list")
    public RestResp list(Integer workDirection){

        RestResp list = iBookInfoService.getList(workDirection);

        return list;
    }

}
